// import axios from "axios";
import http from "@/api/config";
// var root = "http://127.0.0.1:8888/addons/up_depot/inc/web/public";
var root = "/addons/up_depot/inc/web/public";
import { Message } from "element-ui";

/**
 * 获取仓库列表信息
 * @param type 类型，1：仓库，2：门店
 * @param page 当前页
 * @param limit 每页显示条数
 * @param callback
 */
const storehouse_getAll = (type, page, limit, callback) => {
  var url = root + "/Storehouse/getAll";
  let data = new FormData();
  data.append("type", type);
  data.append("page", page);
  data.append("limit", limit);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取仓库列表信息
 * @param type 类型，1：仓库，2：门店
 * @param page 当前页
 * @param limit 每页显示条数
 * @param callback
 */
const storehouse_getAllByUniacid = callback => {
  var url = root + "/Storehouse/getAllByUniacid";

  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 增加仓库或者修改仓库数据
 * data参数说明
 * @param $id 如果有ID那么是修改，没有ID事新增
 * @param $type 类型，1：仓库，2：门店    必填
 * @param $name 仓库名称    必填
 * @param $intro 仓库介绍
 * @param $code 仓库代码
 * @param $position 仓库位置
 * @param $address 仓库地址
 */
const storehouse_save = (data, callback) => {
  var url = root + "/Storehouse/save";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 删除仓库
 * @param id 需要删除的唯一ID
 * @param callback
 */
const storehouse_del = (id, callback) => {
  var url = root + "/Storehouse/del";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 删除仓库
 * @param id 需要删除的唯一ID
 * @param callback
 */
const storehouse_getInfoById = (id, callback) => {
  var url = root + "/Storehouse/getInfoById";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 云服务初始化
 * @param id 需要删除的唯一ID
 * @param callback
 */
const cloudSetting_getInfoByUniacid = callback => {
  var url = root + "/CloudSetting/getInfoByUniacid";

  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 存储配置初始化
 * @param id 需要删除的唯一ID
 * @param callback
 */
const memory_getInfoByUniacid = callback => {
  var url = root + "/Memory/getInfoByUniacid";

  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 修改
 * @param id 需要删除的唯一ID
 * @param callback
 */
const memory_update = (data, callback) => {
  var url = root + "/Memory/update";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 测试存储参数配置
 * @param id 需要删除的唯一ID
 * @param callback
 */
const memory_memorytest = (data, callback) => {
  var url = root + "/Memory/memorytest";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取用户列表
 * @param callback
 */
const users_getAll = (page, limit, callback) => {
  var url = root + "/Users/getAll";

  let data = new FormData();
  data.append("page", page);
  data.append("limit", limit);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取用户分组
 * @param callback
 */
const group_getAll = callback => {
  var url = root + "/Group/getAll";

  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 保存用户
 * data参数说明
 * @param id 如果有ID那么是修改，没有ID事新增
 * @param name 仓库名称    必填
 * @param phone 手机号码
 * @param group_id 分组的ID
 * @param storehouse_id 仓库或者门店的ID
 */
const users_save = (data, callback) => {
  var url = root + "/Users/save";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 删除用户
 * data参数说明
 * @param id
 */
const users_del = (id, callback) => {
  var url = root + "/Users/del";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 根据ID获取用户详细信息
 * data参数说明
 * @param id
 */
const users_getInfoById = (id, callback) => {
  var url = root + "/Users/getInfoById";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 根据ID获取用户详细信息
 * data参数说明
 * @param id
 */
const brand_getAll = (page, limit, callback) => {
  var url = root + "/Brand/getAll";
  let data = new FormData();
  data.append("page", page);
  data.append("limit", limit);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 保存品牌
 * data参数说明
 * @param id 如果有ID那么是修改，没有ID事新增
 * @param name 品牌名
 * @param en_name 英文名
 * @param contacts_name 联系人
 * @param phone 手机号码
 */
const brand_save = (data, callback) => {
  var url = root + "/Brand/save";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};
/**
 * 删除品牌
 * data参数说明
 * @param id
 */
const brand_del = (id, callback) => {
  var url = root + "/Brand/del";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 编辑品牌
 * data参数说明
 * @param id
 */
const brand_getInfoById = (id, callback) => {
  var url = root + "/Brand/getInfoById";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 根据父ID获取子分类
 * data参数说明
 * @param id
 */
const classify_getAllByFid = (fid, callback) => {
  var url = root + "/Classify/getAllByFid";
  let data = new FormData();
  data.append("fid", fid);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 根据父ID获取子分类
 * data参数说明
 * @param id
 */
const classify_getInfoById = (id, callback) => {
  var url = root + "/Classify/getInfoById";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取资源文件前缀
 * data参数说明
 * @param id
 */
const memory_getFileUrl = callback => {
  var url = root + "/Memory/getFileUrl";
  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取资源文件前缀
 * data参数说明
 * @param id
 */
const memory_uploadfile = (file, callback) => {
  var url = root + "/Memory/uploadfile";

  let data = new FormData();
  data.append("image", file);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 删除分类
 * data参数说明
 * @param id
 */
const classify_del = (id, callback) => {
  var url = root + "/Classify/del";

  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 获取资源文件前缀
 * data参数说明
 * @param id
 */
const classify_getAll = callback => {
  var url = root + "/Classify/getAll";

  http.post(url).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 修改父亲级节点
 * data参数说明
 * @param id
 */
const classify_updateFidById = (id, fid, callback) => {
  var url = root + "/Classify/updateFidById";

  let data = new FormData();
  data.append("id", id);
  data.append("fid", fid);

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

/**
 * 增加仓库或者修改仓库数据
 */
const classify_save = (data, callback) => {
  var url = root + "/Classify/save";

  http.post(url, data).then(res => {
    if (res.status == 200) {
      callback(res.date);
    } else {
      Message.error("网络异常");
    }
  });
};

export {
  storehouse_getAll,
  storehouse_getAllByUniacid,
  storehouse_save,
  storehouse_del,
  storehouse_getInfoById,
  cloudSetting_getInfoByUniacid,
  memory_getInfoByUniacid,
  memory_update,
  memory_memorytest,
  users_getAll,
  group_getAll,
  users_save,
  users_del,
  users_getInfoById,
  brand_getAll,
  brand_save,
  brand_del,
  brand_getInfoById,
  classify_getAllByFid,
  classify_getInfoById,
  memory_getFileUrl,
  memory_uploadfile,
  classify_del,
  classify_getAll,
  classify_updateFidById,
  classify_save
};
